import {
  setToken
} from '@/utils/auth'

function getRequest() {
  var url = window.location.search; //获取url中"?"符后的字串
  // var url = 'https://bee.xiaodaiyan.com/screen/?token=123456789'
  var theRequest = new Object();
  if (url.indexOf("?") != -1) {
    // var index = url.indexOf("?")
    var str = url.substr(1);
    var strs = str.split("&");
    console.log('strs', strs)

    console.log('长度', strs.length)
    if (strs.length > 1) {
      //缓存areaId
      var areaId = strs[1].slice(7)
      console.log(areaId)
      localStorage.setItem('areaId', areaId)

      //缓存areaName
      var urls = decodeURI(url.substr(1)); //处理中文乱码
      // console.log(urls)
      var areaName = urls.split('areaName=')[1]
      console.log(areaName)
      localStorage.setItem('areaName', areaName)
    }

    for (var i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
    }
  }
  return theRequest;
}
var token = getRequest().token;
// console.log('token123',token)
setToken(token)